package de.g18.gruppe3.gui.view;

import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class SQLConnectionView extends JFrame {
	
	/**
	 * Screen zur Eingabe einer SQL Connection.
	 * Wird für den Zugriff auf die Datenbank benötigt.
	 *
	 * @author <a href="madmakro@gmx.net">Jan Schwart</a>
	 */

	private static final long serialVersionUID = 1001L;
	private JPanel pUCSqlViewMain = new JPanel();
	private JPanel pUCSqlViewTop = new JPanel();
	private JPanel pUCSqlViewBottom = new JPanel();
	private JLabel lUCSqlViewConnection = new JLabel("Datenbank: ");
	private JLabel lUCSqlViewLogin = new JLabel("Loginname: ");
	private JLabel lUCSqlViewPasswort = new JLabel("Passwort: ");
	private JTextField tfUCSqlViewConnection = new JTextField();
	private JTextField tfUCSqlViewLogin = new JTextField();
	private JPasswordField pfCSqlViewPasswort = new JPasswordField();
	
	private JButton bUCSqlOk = new JButton("OK");
	private JButton bUCSqlChancel = new JButton("Abbrechen");
	
	//Konstruktor
	public SQLConnectionView(String title) {
		super(title);
		initializeComponents();
		
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    
	    setLayout(new BorderLayout());
	    setSize(320, 180);
	    setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-(getWidth()/2),
	    			GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-(getHeight()/2));
	    setResizable(false);
	    setVisible(true);
	    
	    add(pUCSqlViewMain, BorderLayout.NORTH);
	    add(pUCSqlViewBottom, BorderLayout.SOUTH);
				
	}
	
	//Initialisierung der GUI-Komponenten
	private void initializeComponents() {
		
		//Top Panel:
		pUCSqlViewTop.setLayout(new GridLayout(3, 2, 6, 6));
		pUCSqlViewTop.setBorder(BorderFactory.createTitledBorder("SQL-Verbindung"));
		pUCSqlViewTop.add(lUCSqlViewConnection);
		pUCSqlViewTop.add(tfUCSqlViewConnection);
		pUCSqlViewTop.add(lUCSqlViewLogin);
		pUCSqlViewTop.add(tfUCSqlViewLogin);
		pUCSqlViewTop.add(lUCSqlViewPasswort);
		pUCSqlViewTop.add(pfCSqlViewPasswort);
		
		//Bottom Panel:
		pUCSqlViewBottom.setLayout(new GridLayout(1, 2));
		pUCSqlViewBottom.add(getbUCSqlOk());
		pUCSqlViewBottom.add(getbUCSqlChancel());
		
		//Main Panel:
		pUCSqlViewMain.setLayout(new GridLayout());
		pUCSqlViewMain.setBorder(BorderFactory.createEmptyBorder(8, 12, 4, 12));
		pUCSqlViewMain.add(pUCSqlViewTop);
		
	}

	//Getter & Setter

	public JTextField gettfUCSqlConnection() { return tfUCSqlViewConnection; };
	public JTextField gettfUCSqlViewLogin() { return tfUCSqlViewLogin; };
	public JPasswordField getpfCSqlViewPasswort() { return pfCSqlViewPasswort; };
	public JButton getbUCSqlOk() { return bUCSqlOk; };
	public JButton getbUCSqlChancel() { return bUCSqlChancel; };

}
